import BaseView from "../../../cfw/mvc/BaseView";
import CristmasTreeManager from "../model/CristmasTreeManager";
import CristmasTreeController from "../CristmasTreeController";
import ItemView from "../../item/ItemView";

import GridLayerListView from "../../../engine/GridLayerListView";
import SDKManager from "../../../sdk/SDKManager";
import { SDKEventName } from "../../../sdk/SDKConfig";

const { ccclass, property } = cc._decorator;

@ccclass
export default class CristmasTreeRoom extends BaseView {


    @property(GridLayerListView)
    leftScrollView: GridLayerListView = null;


    @property(GridLayerListView)
    rightScrollView: GridLayerListView = null;





    @property(cc.Prefab)
    itemPrefab: cc.Prefab = null;


    protected model: CristmasTreeManager;
    protected controller: CristmasTreeController;
    start() {
        let lights = this.model.getLightList()
        cc.log(' lights ', lights.length)
        this.leftScrollView.totalCount = lights.length

        let toys = this.model.getToyList()
        this.rightScrollView.totalCount = toys.length
        SDKManager.getChannel().sendEvent(SDKEventName.entertree)
    }

    leftListViewUpdate(listView, pos: number, item: cc.Node) {
        let lights = this.model.getLightList()
        let comp: ItemView = this.controller.initView(item, 'ItemView', lights[pos]) as ItemView
        // if (comp.isLoad()) {
        comp.refresh()
        // }
    }

    rightListViewUpdate(listView, pos: number, item: cc.Node) {
        // let columnList = this.model.getColumnList()
        // cc.log(" rightListViewUpdate ",pos)
        let toys = this.model.getToyList()
        let comp: ItemView = this.controller.initView(item, 'ItemView', toys[pos]) as ItemView
        // if (comp.isLoad()) {
        comp.refresh()
        // }
    }

    // rightListViewUpdate2(listView, pos: number, item: cc.Node) {
    //     // let columnList = this.model.getColumnList()
    //     // cc.log(" rightListViewUpdate ",pos)
    //     let toys = this.model.getToyList()
    //     let comp: ItemView = this.controller.initView(item, 'ItemView', toys[pos]) as ItemView
    //     // if (comp.isLoad()) {
    //     comp.refresh()
    //     // }
    // }
    onButtonBackClick() {
        this.controller.back();
    }

}
